package com.example.carshiro.factory;


import com.example.carshiro.filter.MyFormAuthenticationFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.servlet.Filter;
import java.util.LinkedHashMap;

@Component
public class FilterChainDefinitionMapBuilder {

    @Autowired
    private MyFormAuthenticationFilter myFormAuthenticationFilter;



    @Bean("myFilterMap")
    public LinkedHashMap<String,String> buildFilterChainDefinitionMap(){

        LinkedHashMap<String,String> map = new LinkedHashMap<>();

        map.put("/login.jsp", "anon");
        map.put("/login","anon");
        map.put("/loginToken","anon");
        map.put("/reg", "anon");
        map.put("/myshiro/logout", "logout");
        map.put("/user/list", "roles[user]");
        map.put("/admin/list", "roles[admin]");
        map.put("/index.jsp","myFilter1");
        map.put("/**", "authc");
        return map;
    }

    @Bean("myFilters")
    public LinkedHashMap<String, Filter> setFilters(){
        LinkedHashMap<String, Filter> filterMap=new LinkedHashMap<>();
        filterMap.put("myFilter1",myFormAuthenticationFilter);
        return filterMap;
    }
}
